package com.example.demo.zookeeper.config;

import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * @author liweizhi
 * @date 2020/6/21
 */
public class ZkUtil {
    private static final CountDownLatch LATCH = new CountDownLatch(1);
    private static final DefaultWatch DEFAULT_WATCH = new DefaultWatch(LATCH);
    private static final int SESSION_TIMEOUT = 30000;
    private static final String CONNECT_STRING = "192.168.200.11:2181,192.168.200.12:2181,192.168.200.13:2181,192.168.200.14:2181/testConfig";
    public static ZooKeeper zk;

    static {
        initZk();
    }

    public static void initZk() {
        try {
            zk = new ZooKeeper(CONNECT_STRING, SESSION_TIMEOUT, DEFAULT_WATCH);
            LATCH.await();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
